package com.ss.android.article.base.feature.detail2.d;

import android.net.Uri;
import android.os.Bundle;

import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.detail.model.ArticleDetail;
import com.ss.android.article.base.feature.feed.presenter.ListData;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.model.CellRef;

import org.json.JSONException;
import org.json.JSONObject;

public final class NewDetailContext {
    public boolean fromNotification;
    public boolean bundleNoHwAcceleration;
    public int previousTaskId;
    public String previousTaskIntent;
    public boolean bundleForbidJump;
    private long flags;
    private long fromGid;
    private String gdExtJson;
    private boolean I;
    private AppData mAppData;
    public boolean viewSingleId;
    public long adId;
    public String logExtra;
    public JSONObject logPb;
    public long searchResultId;
    public String query;
    public String source;
    public long group_id;
    public long item_id;
    public int aggrType;
    public int groupFlags;
    public int articleType;
    public Article article;
    public ArticleDetail articleDetail;
    public Uri extraSchemaUri;
    public String articleUrl;
    public int listType;
    public String categoryName;
    public boolean s;
    public boolean isJumpComment;
    public boolean showWriteCommentDialog;
    public String detailSource;
    public int stayTT;
    public String growthFrom;
    public long _itemId;
    public long commentId;

    public NewDetailContext() {
        this.groupFlags = 0;
        this.articleType = -1;
        this.s = false;
        this.isJumpComment = false;
        this.showWriteCommentDialog = false;
        this.detailSource = null;
        this.stayTT = 1;
        this.gdExtJson = null;
        this._itemId = 0;
        this.commentId = 0;
        this.fromNotification = false;
        this.bundleNoHwAcceleration = false;
        this.previousTaskId = -1;
        this.previousTaskIntent = null;
        this.mAppData = AppData.getInstance();
    }

    public final JSONObject a() {
        JSONObject v0 = null;
        try {
            if (android.support.design.a.isTextEmpty(this.gdExtJson)) {
            } else {
                v0 = new JSONObject(this.gdExtJson);
            }


            if (v0 == null) {
                v0 = new JSONObject();
            }
            if (this.fromGid > 0) {
                v0.put("from_gid", this.fromGid);
            }

            if (this.logPb != null) {
                v0.put("log_pb", this.logPb);
            }

            if (this.categoryName != null) {
                v0.put("category_name", this.categoryName);
            }

            if (this.article == null) {
                return v0;
            }

            v0.put("user_id", this.article.getUserId());
        } catch (JSONException e) {

        }

        return v0;
    }

    public final boolean a(Bundle bundle) {
        long v8 = 0;
        if (bundle == null) {
            return false;
        }

        this.bundleNoHwAcceleration = bundle.getBoolean("bundle_no_hw_acceleration", false);
        this.fromNotification = bundle.getBoolean("from_notification", false);
        this.gdExtJson = bundle.getString("gd_ext_json");
        this.categoryName = bundle.getString("category");
        bundle.getString("enter_from");
        boolean isJumpComment = bundle.getBoolean("is_jump_comment", false);
        this.isJumpComment = isJumpComment;
        this.s = isJumpComment;
        this.showWriteCommentDialog = bundle.getBoolean("show_write_comment_dialog", false);
        if (bundle.containsKey("detail_source")) {
            this.detailSource = bundle.getString("detail_source");
        } else if (this.fromNotification) {
            this.detailSource = "click_apn";
        }

        if (bundle.containsKey("stay_tt")) {
            this.stayTT = bundle.getInt("stay_tt");
            if (this.stayTT == 0) {
                this.previousTaskId = bundle.getInt("previous_task_id");
                this.previousTaskIntent = bundle.getString("previous_task_intent");
            }
        }

        this.growthFrom = bundle.getString("growth_from");
        this.viewSingleId = bundle.getBoolean("view_single_id", false);
        this.extraSchemaUri = bundle.getParcelable("extra_schema_uri");
        String v0_1 = bundle.getString("log_pb", "");
        if (!android.support.design.a.isTextEmpty(v0_1)) {
            try {
                this.logPb = new JSONObject(v0_1);
            } catch (JSONException v0_2) {
            }
        }

        if (!android.support.design.a.isTextEmpty(this.gdExtJson)) {
            try {
                JSONObject v0_3 = new JSONObject(this.gdExtJson);
                this.searchResultId = v0_3.optLong("search_result_id", 0);
                this.query = v0_3.optString("query");
                this.source = v0_3.optString("source");
                if (this.logPb != null) {
                } else {
                    this.logPb = new JSONObject(v0_3.optString("log_pb"));
                }
            } catch (JSONException v0_2) {
            }
        }

        if (this.viewSingleId) {
            this.group_id = bundle.getLong("group_id", v8);
            this.item_id = bundle.getLong("item_id", v8);
            this.aggrType = bundle.getInt("aggr_type", 0);
            this.flags = bundle.getLong("flags", v8);
            if (this.flags != v8) {
                if ((this.flags & 65536) > v8) {
                    this.groupFlags |= 131072;
                }

                if ((this.flags & 64) > v8) {
                    this.groupFlags |= 64;
                }

                if ((this.flags & 262144) > v8) {
                    this.groupFlags |= 262144;
                }

                this.articleType = ((int) (this.flags & 1));
            } else {
                this.groupFlags = bundle.getInt("group_flags", 0);
                this.articleType = bundle.getInt("article_type", -1);
            }

            if (this.group_id <= v8) {
                return false;
            }

            this.fromGid = bundle.getLong("from_gid", v8);
            this.adId = bundle.getLong("ad_id", v8);
            if (this.adId > v8) {
                this.articleUrl = bundle.getString("article_url");
                this.logExtra = bundle.getString("bundle_download_app_extra");
                this.bundleForbidJump = bundle.getBoolean("bundle_forbid_jump", false);
            }

            v0_1 = Article.a(this.group_id, this.item_id);
            if (this.item_id <= v8) {
            } else {
                this.article = this.mAppData.e(v0_1);
            }
        } else {
            this.listType = bundle.getInt("list_type", 0);
            if (this.listType != 1 && this.listType != 2 && this.listType != 9 && this.listType != 8 && this.listType != 10 && this.listType != 3 && this.listType != 4) {
                return false;
            }

            if (this.listType == 1 && (android.support.design.a.isTextEmpty(this.categoryName))) {
                return false;
            }

            ListData v0_4 = this.mAppData.a(this.listType, this.categoryName);
            if (v0_4 == null) {
                return false;
            }

            if (v0_4.a != null && !v0_4.a.isEmpty()) {
                boolean v4 = bundle.getBoolean("view_comments", false);
                int v0_5 = v0_4.b;
                if (v0_5 >= 0 && v0_5 < v0_4.a.size()) {
                    CellRef v0_6 = v0_4.a.get(v0_5);
                    if (v0_6 != null && (v0_6.a()) && ((CellRef) v0_6).article != null) {
                        this.adId = v0_6.adId;
                        this.article = v0_6.article;
                        if (this.article != null) {
                            this.article.ah = ((CellRef) v0_6).isSubscribe;
                        }

                        this.group_id = this.article.groupId;
                        this.item_id = this.article.itemId;
                        this.aggrType = this.article.aggrType;
                        this.groupFlags = this.article.groupFlags;
                        this.articleType = this.article.articleType;
                        if (this.adId <= v8) {

                        } else {
                            this.logExtra = ((CellRef) v0_6).logExtra;
                        }
                    }

                    if (!v4) {

                    } else if (this.article == null) {

                    } else {
                        this._itemId = this.article.groupId;
                        if (this.article.comment == null) {

                        } else {
                            this.commentId = this.article.comment.commentId;
                        }
                    }
                }

                if (this.article != null) {
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }

        if (!this.bundleNoHwAcceleration) {
            this.bundleNoHwAcceleration = this.mAppData.forceNoHwAcceleration();
        }
        return true;
    }

    public final String getEnterFrom() {
        String v0 = this.detailSource;
        if (android.support.design.a.isTextEmpty(v0)) {
            if (this.listType == 1) {
                if ("__all__".equals(this.categoryName)) {
                    v0 = "click_headline";
                } else if (!android.support.design.a.isTextEmpty(this.categoryName)) {
                    v0 = "click_" + this.categoryName;
                }
            } else if (this.listType == 3) {
                v0 = "click_search";
            } else if (this.listType == 4) {
                v0 = "click_pgc_list";
            } else if (this.listType == 2) {
                v0 = "click_favorite";
            } else if (this.listType == 8) {
                v0 = "click_read_history";
            } else if (this.listType == 9) {
                v0 = "click_push_history";
            } else if (this.listType == 10) {
                v0 = "click_refresh_history";
            }
        }
        return v0;
    }

    public final boolean hasArticleUrl() {
        return this.article != null && this.article.hasArticleUrl();
    }

    public final boolean isGallery() {
        boolean v0 = true;
        if ((this.groupFlags & 131072) <= 0
                || this.articleType != 1
                && this.articleType != 0) {
            v0 = false;
        }

        return v0;
    }

    public final boolean isVideo() {
        this.I = android.support.design.a.b(((long) this.groupFlags));
        if (this.I) {
            if (this.viewSingleId) {
                if (this.article == null) {
                    return this.I;
                } else if (this.article.hasVideo()) {
                    return this.I;
                }
            } else if (this.article != null) {
                if (this.article.hasVideo()) {
                    return this.I;
                }
            }
            this.I = false;
        }
        return this.I;
    }

    public final boolean isNativePicGroup() {
        return (this.groupFlags & 131072) > 0 && this.articleType == 0;
    }
}

